package com.zzy.controller;

import com.zzy.model.AjaxMsg;
import com.zzy.service.ActivityConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

//import org.activiti.engine.task.Task;


@RestController
@RequestMapping("/flow/")
//http://localhost:8087/activiti/bpmn/list
public class ActivitiController {
    @Autowired
    private ActivityConsumerService activityConsumerService;

    /** 所有的流程 bpmn 文件  */
    @RequestMapping("bpmn/list")
    public AjaxMsg bpmnList(){
        List list = activityConsumerService.getFlowBpmnList();
        return AjaxMsg.returnAjaxMsg(list);
    }

    /**部署流程*/
    @RequestMapping("deploy")
    public AjaxMsg deployFlow(@RequestParam(value = "processName", required = false) String processName){
        activityConsumerService.deployFlow(processName);
        return AjaxMsg.returnAjaxMsg();
    }
    /**取消部署流程*/
    public AjaxMsg cancalDeployFlow(@RequestParam(value = "processDefinitionId", required = false) String  processDefinitionId){
        activityConsumerService.cancalDeployFlow(processDefinitionId);
        return AjaxMsg.returnAjaxMsg();
    }

    /** 已经 部署的 流程   */
    @RequestMapping("deployed/list")
    public AjaxMsg deployedList(){
        List<Map<String,Object>>  list = activityConsumerService.getDeployedList();
        return AjaxMsg.returnAjaxMsg(list);
    }


    /** 发起流程 */
    @RequestMapping("start")
    public AjaxMsg startFlow(@RequestParam Map<String,String> map){
        activityConsumerService.startFlow(map);
        return AjaxMsg.returnAjaxMsg();
    }
    /** 取消发起流程[删除已经发起的流程]*/
    @RequestMapping("cancal")
    public AjaxMsg cancalStartedFlow(String processInstanceId,String userId){
        activityConsumerService.cancalStartedFlow(processInstanceId,userId);
        return AjaxMsg.returnAjaxMsg();
    }
    /** 获取待处理的流程[获取代办]*/
    public AjaxMsg getFlowTask(String userId){
        activityConsumerService.getFlowTask( userId);
        return AjaxMsg.returnAjaxMsg();
    }
    /** 完成任务[完成代办]*/
    public AjaxMsg completeTask(@RequestParam Map<String,String> map){
        activityConsumerService.completeTask(map);
        return AjaxMsg.returnAjaxMsg();
    }
    /** 退回流程[审核不通过]*/
    @RequestMapping("revert")
    public AjaxMsg revertTask(@RequestParam Map<String,String> map){
        activityConsumerService.revertTask(map);
        return AjaxMsg.returnAjaxMsg();
    }

    /** 获取流程图 */
    @RequestMapping("image")
    public void image(String processInstanceId, HttpServletResponse response){
        activityConsumerService.getGraphics(processInstanceId,response);
    }

    @RequestMapping("test")
    public AjaxMsg test(String runId){
        return AjaxMsg.returnAjaxMsg();
    }
}
